package rms.mall.server.domain.config;

import cn.dev33.satoken.stp.StpUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import rms.mall.server.domain.context.CommonContext;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component

public class WebFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        if (StpUtil.isLogin()) {
            CommonContext.get().setAcctId(StpUtil.getLoginIdAsLong());
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
